import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
    const userId = ref('');
    const username = ref('');
    const password = ref('');
    const role = ref('');

    const login = (user) => {
        userId.value = user.userId;
        username.value = user.username;
        password.value = user.password;
        role.value = user.role;
    }
    const logout = () => {
        userId.value = '';
        username.value = '';
        password.value = '';
        role.value = '';
    }
  return { userId, username, password, role, login,logout }
},
{
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'user',
          storage: localStorage,
        },
      ],
    },
})
